/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package assignment2.stub;

import assignment2.data.Customers;
import assignment2.data.CustomersFacade;
import assignment2.data.Users;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;

/**
 *
 * @author tuan
 */
public class CustomerTbl_Stub {

    CustomersFacade customersFacade = lookupCustomersFacadeBean();

    public List<Customers> listAll() {
        return customersFacade.findAll();
    }
    public Customers findByUserName(String userName){
        return customersFacade.findByUserName(userName);
    
    }

    public Customers searchByID(String customerID) {
        return customersFacade.find(customerID);

    }
    
    public Customers searchByUsername(Users username){
        return customersFacade.find(username);
    }

    public void insert(Customers customer) {
        customersFacade.create(customer);

    }

    public void modify(Customers customer) {
        customersFacade.edit(customer);

    }

    public void remove(Customers customer) {
        customersFacade.remove(customer);
    }

    private CustomersFacade lookupCustomersFacadeBean() {
        try {
            Context c = new InitialContext();
            return (CustomersFacade) c.lookup("java:global/Assignment2/Assignment2-ejb/CustomersFacade!assignment2.data.CustomersFacade");
        } catch (NamingException ne) {
            Logger.getLogger(getClass().getName()).log(Level.SEVERE, "exception caught", ne);
            throw new RuntimeException(ne);
        }
    }
}
